#include<sstream>
#include<iostream>
#include<algorithm>
#include <string>
using namespace std;
const int N=1e5+10;
int n,a[N];
int main()
{
        int cnt=0;
        cin>>cnt;
        string line;
        int n=0;
        getline(cin,line);
        while(cnt--)
        {
            getline(cin,line);
            stringstream ccin(line);
            while(ccin>>a[n])n++;
        }
        sort(a,a+n);
        int res1=0,res2=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i-1])res1=a[i];
            else if(a[i]>=a[i-1]+2)res2=a[i]-1;
        }
        cout<<res2<<" "<<res1;
}